<?php
/**
 * Prado Portal.
 *
 * @author Steen Rabol <steen.rabol@gmail.com>
 * @link http://www.pradoportal.dk/
 * @copyright Copyright &copy; 2006,2007,2008 Steen Rabol
 * @license http://www.pradoportal.dk
 * @version $Id: VListMenuPortlet.php 426 2011-01-05 10:36:10Z steen.rabol $
 *
 */

Prado::using('Application.Portlets.Portlet');
Prado::using('Application.Common.Data.PortalSiteMenuRecord');
class VListMenuPortlet extends Portlet
{
	private $_sitemenid		= -1;
	private $_menuheader	= 'Menu header';

	protected function getConfigName()
	{
		return get_class() . '_' . $this->Parameters['id'];
	}
	
	public function  onLoad($param) 
	{
		parent::onLoad($param);
	
		$cValues = Prado::unserialize($this->ConfigRecord->value);
		if($cValues && is_array($cValues) && count($cValues))
		{
			if(isset($cValues['sitemenuid']))
			{
				$this->SiteMenuId	= TPropertyValue::ensureInteger($cValues['sitemenuid']);
			}
			else
			{
				$this->SiteMenuId	= -1;
			}

			if(isset($cValues['menuheader']))
			{
				$this->MenuHeader	= TPropertyValue::ensureString($cValues['menuheader']);
			}
			else
			{
				$this->MenuHeader	= 'Menu header';
			}
		}

		$this->tlMenuHeader->Text		= "<h3 class=\"vlistmenuheaderbar\">". $this->MenuHeader . "</h3>";
		$this->ddlMenus->DataSource		= PortalSiteMenuRecord::finder()->findAllByactive(1);
		$this->ddlMenus->SelectedValue	= $this->SiteMenuId;
		$this->ddlMenus->dataBind();
	}

	public function getSiteMenuId()
	{
		return $this->_sitemenid;
	}

	public function setSiteMenuId($value)
	{
		$this->_sitemenid	= TPropertyValue::ensureInteger($value);
	}

	public function getMenuHeader()
	{
		return $this->_menuheader;
	}

	public function setMenuHeader($value)
	{
		$this->_menuheader	= TPropertyValue::ensureString($value);
	}

	public function CancelContent($sender,$param)
	{
		$this->ddlMenus->SelectedValue = $this->getSiteMenuId();
	}

	public function SaveContent($sender,$param)
	{
		$item						= $this->ddlMenus->Items[$this->ddlMenus->SelectedIndex];
		$this->SiteMenuId			= $item->value;
		$this->MenuHeader			= $item->text;
		$this->ConfigRecord->value	= Prado::serialize(array('sitemenuid' => $this->SiteMenuId,'menuheader' => $this->MenuHeader));
		$this->ConfigRecord->save();
		$this->Page->gotoPage($this->Parameters['pagename'],array("PageMode" => $this->Page->EditMode));
	}
}
?>
